//
//  UIView+.swift
//  MoodDiary
//
//  Created by OVIX on 2020/12/15.
//

import UIKit

extension UIView {
    /// 截屏Image
    var captureImage: UIImage? {
        
        // 参数①：截屏区域  参数②：是否透明  参数③：清晰度
        UIGraphicsBeginImageContextWithOptions(frame.size, true, UIScreen.main.scale)
        layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
    
    func getImageFromImage(oldImage:UIImage, newImageRect:CGRect) ->UIImage {
        let imageRef = oldImage.cgImage;
        let subImageRef = imageRef!.cropping(to: newImageRect);
        return UIImage(cgImage: subImageRef!)
    }
    
}
